<?php

namespace Admin\Controllers;

class ReportController extends AuthController {

    public function indexAction() {
        $moneyRecordModel = model("Pay/MoneyRecord");
        $userModel = model("User/User");
        if ($_REQUEST['type']) {
            $condition['type'] = $_REQUEST['type'];
        }
        if ($_REQUEST['userId']) {
            $condition['userId'] = $_REQUEST['userId'];
        }
        if ($_REQUEST['nickname']) {
            $user = $userModel->findFirstByNickname($_REQUEST['nickname']);
            if ($user) {
                $condition['userId'] = $user->getId();
            } else {
                $condition['userId'] = 0;
            }
        }
        if (empty($_REQUEST['createTime'])) {
            $_REQUEST['createTime'] = date("Y-m-d", strtotime("-6 day"));
        }
        if (empty($_REQUEST['endTime'])) {
            $_REQUEST['endTime'] = date("Y-m-d", strtotime("0 day"));
        }
        $time['createTime'] = strtotime($_REQUEST['createTime']);
        $time['endTime'] = strtotime($_REQUEST['endTime']) + 24 * 3600 - 1;
        $condition['createTime'] = array("BETWEEN", array($time['createTime'], $time['endTime']));
        $count = $moneyRecordModel->getCountNumber($condition);
        $list = $moneyRecordModel->getLists($condition, $fieldArr = array(), $moneyRecordModel->getPk() . " desc", $page = $_REQUEST['p'] ? $_REQUEST['p'] : 1, $pagesize = 10, $groupStr = "");
        //分页类
        $Page = new \Platform\Libs\Page($count, PAGE_SIZE);
        if ($list) {
            //获取所有管理员用户信息
            $userList = $userModel->getDateListBySelectDate($list, "userId", "id,nickname", "userId");
            foreach ($list as $key => $value) {
                $list[$key]['userName'] = $userList[$key]['nickname'];
            }
        }
        //分页跳转的时候保证查询条件
        foreach ($_REQUEST as $key => $val) {
            if ($key != "_url" && $val) {
                $Page->parameter .= "$key=" . urlencode($val) . "&";
            }
        }
        $show = $Page->show();
        $this->view->show = $show;
        $this->view->list = $list;
        $this->view->pick("report/moneyRecord");
    }

}
